#include "stdafx.h"

const double WaveBullet::rotateSpeed = 50;

WaveBullet::WaveBullet(double x, double y)
	:AbstractBullet(x, y)
{
}

WaveBullet::~WaveBullet()
{
}

void WaveBullet::setImage(const std::string & filename)
{
	img = ImageMgr::getInstance()->get(filename);
}

bool WaveBullet::update(double dtime)
{
	time += dtime;

	if (time > lifeSpan)
	{
		die();
		return false;
	}

	alpha = 1.0f - time / lifeSpan;
	angle += dtime*rotateSpeed;
	//spread += dtime*spreadVelocity;
	//radius += dtime*spreadVelocity;
	radius = time*time*spreadVelocity * 25;

	if (hurting)
	{
		hurtTime += dtime;
		if (hurtTime > hurtInterval)
		{
			hurting = false;
			hurtTime = 0;
		}
	}

	if (hurting == false)
	{
		if (hero->distance(x, y) < radius)
		{
			if (!hero->isSheilded())
			{
				hero->loseHP(damage);
			}

			hurting = true;
		}
	}

	return true;
}

bool WaveBullet::render()
{
	img->render(getDisplayX(), getDisplayY(), 2 * radius, 2 * radius, angle);

	return true;
}

void WaveBullet::die()
{
	
}